package com.lemon.reggie.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lemon.reggie.common.R;
import com.lemon.reggie.pojo.dto.CategoryDTO;
import com.lemon.reggie.pojo.entity.Category;
import com.lemon.reggie.pojo.entity.Employee;
import com.lemon.reggie.pojo.vo.CategoryVO;
import com.lemon.reggie.pojo.vo.FrontIndexVO;
import com.lemon.reggie.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 前端控制器
 * </p>
 *
 * @author Lemon
 * @since 2022-05-23
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/page")
    public R<?> pageCategory(@RequestParam("page") Long currentPage, @RequestParam("pageSize") Long pageSize) {
        IPage<Category> page = categoryService.pageCategory(currentPage, pageSize);
        return R.success(page);
    }

    @PostMapping
    public R<?> saveCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.saveCategory(categoryDTO);
        return R.success("添加成功！");
    }

    @DeleteMapping
    public R<?> deleteCategory(@RequestParam("ids") String id) {
        categoryService.deleteCategory(id);
        return R.success("删除成功！");
    }

    @PutMapping
    public R<?> editCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.editCategory(categoryDTO);
        return R.success("修改成功！");
    }

    @GetMapping("/list")
    public R<?> listCategory(@RequestParam(value = "type",required = false) Integer type) {
        List<CategoryVO> categoryVOS = categoryService.listCategory(type);
        return R.success(categoryVOS);
    }

}

